<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8" %> 
<%@ page language="java" import="javazoom.upload.*"%> 
<%@ page import="java.text.SimpleDateFormat"%> 
<%@ page import="java.io.*"%> 
<%@ page import="java.util.*"%> 
<%@ page import="javazoom.upload.*"%> 
<%@ page import="uploadutilities.FileMover"%> 
<%@ include file="common/head.jsp" %>
<% 
	request.setCharacterEncoding("utf-8");//设置编码格式，就不用一个个转码了。 
	FileMover fileMover = new FileMover();//你也可以使用自带的实例中jsp:useBean的形式。 
	UploadBean upBean = new UploadBean(); 
	MultipartFormDataRequest mrequest = null; 
	Hashtable files = null; 
	StringBuffer buffer = new StringBuffer();
	buffer.append("\r\n");
	String mols = "s";
	if (MultipartFormDataRequest.isMultipartFormData(request)) 
	{ 
		mrequest = new MultipartFormDataRequest(request,null,100*1024*1024,MultipartFormDataRequest.COSPARSER,"utf-8");//注意这里也要设置编码参数 
		//这里用来测试title参数是否正确。调试的时候，加一句if (true)return;即可。 
		files = mrequest.getFiles(); 
	} 
	
	String sWebRootPath = getServletContext().getRealPath("/");//得到你的web应用的根。 
	String sPath=sWebRootPath+"molTemp"; 
	String sServerFileName=""; 
	String sLocalFileName = ""; 
	String str="ThisIsJSPParam";
	//文件获取 
	if ( (files != null) || (!files.isEmpty()) ) 
	{ 
	    
		UploadFile file = (UploadFile) files.get("attach"); 
		sLocalFileName=file.getFileName(); 	//获取上传文件的名称
		int ii= sLocalFileName.indexOf("."); //取文件名的后缀 
		String sExt = sLocalFileName.substring(ii,sLocalFileName.length()); 
		//得到不重复的文件名 
		java.util.Date dt = new java.util.Date(System.currentTimeMillis()); 
		SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS"); 
		sServerFileName= fmt.format(dt); 
		sServerFileName =sServerFileName + sExt; 
		//如果不存在该目录，则新建一个 
		File dir =new File(sPath); 
		if (!dir.exists()){ 
		dir.mkdirs(); 
		} 
		upBean.setFolderstore(sPath);//设置要上传的目录 
		upBean.addUploadListener(fileMover);//增加filMover监听 
		fileMover.setNewfilename(sServerFileName);//设置服务器上的文件名 
		upBean.store(mrequest, "attach");//上传 
		 FileReader fr=new FileReader(sPath+"/"+sServerFileName);//建立FileReader对象，并实例化为fr
		   BufferedReader br=new BufferedReader(fr);//建立BufferedReader对象，并实例化为br
		  
		   String line= null;
		   while((line = br.readLine()) != null)
		   {	
		   buffer = buffer.append(line+"\r\n");
		   	   //buffer = buffer.append(line+"\"+"+"\r\n"+"\"");
		   }
		   
		   //out.println(buffer);//输出从文件中读取到的内容
		   //这里可以插入对读取到的内容筛选，然后用下面的sql语句插入数据
		   fr.close();//关闭文件输出流，不关闭的话，将无法执行最后一步的删除
		   File txtfile=new File(sPath+"/"+sServerFileName);//创建File对象，并获得要操作的文件路径
		   txtfile.delete();//删除
		   
		   request.setAttribute("value",buffer) ;
		  // str = buffer.toString();
	} 
	//mols = buffer.toString();
	//out.println(mols);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>JME Example 1</TITLE>

<SCRIPT LANGUAGE="JavaScript">

function getSmiles() {
  var drawing = document.JME.smiles();
  document.form.smi.value = drawing;
}

function getJmeFile() {
  var jme = document.JME.jmeFile();
  document.form.jme_output.value = jme;
}

function getMolFile() {
  var mol = document.JME.molFile();
  document.form.mol_output.value = mol;
}

function processJme() {
  document.JME.readMolecule(document.form.jme_output.value);
}

function useMol() {
  document.JME.readMolFile(document.form.mol_output.value);
  document.JMEForm.smiles.value = document.JME.smiles();
  document.JMEForm.jme.value = document.JME.jmeFile();
  document.JMEForm.submit();
}

function readMolecule() {
  var jme = "16 17 C 7.37 -8.99 C 7.37 -7.59 C 6.16 -6.89 C 4.95 -7.59 C 4.95 -8.99 C 6.16 -9.69 N 8.58 -6.89 C 8.58 -5.49 C 7.37 -4.79 O 6.16 -5.49 C 9.80 -7.59 O 9.80 -8.99 C 11.01 -6.89 Cl 12.22 -7.59 Cl 11.01 -5.49 C 9.80 -4.79 1 2 1 2 3 2 3 4 1 4 5 2 5 6 1 6 1 2 7 8 1 8 9 1 9 10 1 3 10 1 2 7 1 7 11 1 11 12 2 11 13 1 13 14 1 13 15 1 8 16 1";
  document.JME.readMolecule(jme);
}

function readMultipart() {
  var jme = "9 9 C 6.68 -7.15 C 5.47 -6.45 C 4.26 -7.15 C 4.26 -8.55 C 5.47 -9.25 C 6.68 -8.55 C 5.47 -5.05 O- 6.68 -4.35 O 4.26 -4.35 1 2 1 2 3 2 3 4 1 4 5 2 5 6 1 6 1 2 2 7 1 7 8 1 7 9 2|1 0 Na+ 12.21 -6.61";
  document.JME.readMolecule(jme)
}

function readReaction() {
  var jme = "3 2 C:1 1.41 -7.12 O:2 1.41 -5.72 Cl 2.63 -7.82 1 2 2 1 3 1|3 2 N:3 5.72 -6.78 C:4 7.12 -6.78 H:5 5.02 -7.99 1 2 1 1 3 1 >> 5 4 C:1 13.51 -6.40 O:2 13.51 -5.00 N:3 14.72 -7.10 C:4 15.94 -6.40 H:5 14.71 -8.50 1 2 2 1 3 1 3 4 1 3 5 1";
  document.JME.readMolecule(jme);
}

function openHelpWindow() {
  window.open("http://www.molinspiration.com/jme/help/jme2008hints.html","jmehelp","toolbar=no,menubar=no,scrollbars=yes,resizable=yes,width=510,height=675,left=400,top=20");
}

</SCRIPT>

</HEAD>
<BODY  BGCOLOR="#FFFFFF">

<center>
<p>
<H2>Analysis Mol File </H2>
<P>
<table border=0 width="100%">
<tr>
<td align="center"> 
<table>
<tr><td>
 <form name="JMEForm" action="${ctx }/search/structure_search.do" method="post" >
 <div class="searchDIV" align="center">
<applet codebase="applet-classes/" code="JME.class" name="JME" archive="JME.jar" width=360 height=315>
You have to enable Java and JavaScritpt on your machine !
</applet>
</div>
<input type="hidden" name="smiles" />
<input type="hidden" name="jme" />
</form>
</td></tr>
<tr><td align="right"><a href="JmeHelp.html" target="_blank">JME Help</a></td></tr>
</table>
</td>
<td align="center">
<FORM METHOD="POST" NAME="form" ONSUBMIT="return false;">
<p>


<b>根据您上传的mol文件分析得到如下信息</b><BR>
<TEXTAREA NAME="mol_output" ROWS=20 COLS=80 readonly="readonly"><%=buffer%></TEXTAREA>
<P>
<INPUT TYPE="button" VALUE="点击提交" onClick="useMol()">
</FORM>
</td>
</tr>
</table>

</center>
<P>
</BODY>
</HTML>

